Interpreting Operands

With ATT syntax, we address the registers, memory, and immediate values using the following symbols:


Examples

  • $-17 represents the integer -17.
  • $0xC represents the integer 12 (that is, C in base 16 is 12 in base 10).
  • 0x108 is a memory address.
  • %rax accesses the value stored at the register addressed withrax.
  • (%rax) accesses the value stored in memory (where rax is holding a memory address, opcode dependent).

Scaling, Shifting, and Indexing

An operand can be given in the format of A ( B, I, S ) where

  • B is a base value that can be indexed, scaled, and shifted with I, S, and A.
  • I represents an index. We add the value of I to the base value B.
  • S is the scale for the index. We scale the value of I by S. The value of S must be 1, 2, 4, or 8.
  • A is a shift, similar to I. We add A to the result of applying I and S to B.

Examples

The following are semi-abstract, descriptive examples that describe the memory address that gets accessed (assuming the instruction we are using would dereference it).

  1. 9(%rax)

    1. Assume rax is storing a memory address.
    2. We shift 9 memory addresses over from the address stored at rax.
    3. We access the value stored at that resulting address.
  2. (%rbx, %rdi)

    1. Assume rbx is storing a memory address.
    2. rdi stores a value that we will add to rbx to get a new memory address.
    3. The parenthesis will tell us to access the value at that final memory address.
  3. -12(%rbx, %rdi)

    1. Assume rbx is storing a memory address.
    2. rdi stores a value we need to add to that memory address to get a resulting memory address
    3. -12 tells us to subtract 12 from the previous memory address to get a new memory address
    4. Access the value at that final memory address.
  4. (,%rdi,4)

    1. rdi is storing a value that gets multiplied by 4
    2. Assume the resulting value is a memory address that we can visit.
    3. We get the value at that memory address.
  5. 10(,%rdi,4)

    1. rdi is storing a value that gets multiplied by 4
    2. Assume the resulting value is a memory address that we can visit.
    3. Shift 10 memory addresses over from the previously resulting memory address.
    4. Access that value.
  6. 10(%rbx, %rdi, 4)

    1. Assume rbx stores a memory location
    2. Multiply the value stored at rdi by 4 and then add the result to the memory location stored in rbx for a new resulting memory address.
    3. Now shift 10 memory addresses over from the previous result.
    4. Access the value at that address.